package com.dcy.factory.simplefactory.pizzastore.order;

import com.dcy.factory.simplefactory.pizzastore.pizza.CheesePizza;
import com.dcy.factory.simplefactory.pizzastore.pizza.GreekPizza;
import com.dcy.factory.simplefactory.pizzastore.pizza.Pizza;

/**
 * @Author：dcy
 * @Description: 简单工厂类
 * @Date: 2021/1/20 13:34
 */
public class SimpleFactory {

    /**
     * 根据orderType 返回Pizza对象
     *
     * @param orderType
     * @return
     */
    public Pizza createPizza(String orderType) {
        System.out.println("使用简单工厂模式");
        Pizza pizza = null;
        // 订购披萨的类型
        if (orderType.equals("greek")) {
            pizza = new GreekPizza();
            pizza.setName(" 希腊披萨 ");
        } else if (orderType.equals("cheese")) {
            pizza = new CheesePizza();
            pizza.setName(" 奶酪披萨 ");
        }
        return pizza;
    }


    /**
     * 简单工厂类 也叫 静态工厂模式
     *
     * @param orderType
     * @return
     */
    public static Pizza createPizza2(String orderType) {
        System.out.println("使用简单工厂模式");
        Pizza pizza = null;
        // 订购披萨的类型
        if (orderType.equals("greek")) {
            pizza = new GreekPizza();
            pizza.setName(" 希腊披萨 ");
        } else if (orderType.equals("cheese")) {
            pizza = new CheesePizza();
            pizza.setName(" 奶酪披萨 ");
        }
        return pizza;
    }
}
